using System.Collections.Generic;
using System.Linq;

namespace JapaneseLearning.Tools
{
    internal static class JapaneseTools
    {
        /// <summary>
        /// 清音
        /// </summary>
        private static readonly string[] Unvoiced =
        {
            "a", "i", "u", "e", "o",
            "ka", "ki", "ku", "ke", "ko",
            "sa", "si", "su", "se", "so",
            "ta", "ti", "tu", "te", "to",
            "na", "ni", "nu", "ne", "no",
            "ha", "hi", "hu", "he", "ho",
            "ma", "mi", "mu", "me", "mo",
            "ya", "yu", "yo",
            "ra", "ri", "ru", "re", "ro",
            "wa", "wo",
        };

        /// <summary>
        /// 浊音
        /// </summary>
        private static readonly string[] Voiced =
        {
            "ga", "gi", "gu", "ge", "go",
            "za", "zi", "zu", "ze", "zo",
            "da", "di", "du", "de", "do",
            "ba", "bi", "bu", "be", "bo",
        };

        /// <summary>
        /// 半浊音
        /// </summary>
        private static readonly string[] SemiVoiced =
        {
            "pa", "pi", "pu", "pe", "po",
        };

        /// <summary>
        /// 拗音
        /// </summary>
        private static readonly string[] AoYin =
        {
            "kya", "kyu", "kyo",
            "gya", "gyu", "gyo",
            "sya", "syu", "syo",
            "zya", "zyu", "zyo",
            "tya", "tyu", "tyo",
            "dya", "dyu", "dyo",
            "nya", "nyu", "nyo",
            "hya", "hyu", "hyo",
            "bya", "byu", "byo",
            "mya", "myu", "myo",
            "rya", "ryu", "ryo",
            "pya", "pyu", "pyo",
        };

        public static string[] GetPingJiaKey(params string[] y)
        {
            var result = new List<string>();
            foreach (var item in y)
            {
                if (item == "qing")
                    result.AddRange(Unvoiced.Select(t => $"{item}_pingj_{t}"));
                if (item == "zhuo")
                    result.AddRange(Voiced.Select(t => $"{item}_pingj_{t}"));
                if (item == "banzhuo")
                    result.AddRange(SemiVoiced.Select(t => $"{item}_pingj_{t}"));
                if (item == "aoyin")
                    result.AddRange(AoYin.Select(t => $"{item}_pingj_{t}"));
            }

            return result.ToArray();
        }

        public static string[] GetPianJiaKey(params string[] y)
        {
            var result = new List<string>();
            foreach (var item in y)
            {
                if (item == "qing")
                    result.AddRange(Unvoiced.Select(t => $"{item}_pianj_{t}"));
                if (item == "zhuo")
                    result.AddRange(Voiced.Select(t => $"{item}_pianj_{t}"));
                if (item == "banzhuo")
                    result.AddRange(SemiVoiced.Select(t => $"{item}_pianj_{t}"));
                if (item == "aoyin")
                    result.AddRange(AoYin.Select(t => $"{item}_pianj_{t}"));
            }

            return result.ToArray();
        }
        
    }
}